package com.kalvin.kvf.modules.xhs.service;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kalvin.kvf.common.utils.ShiroKit;
import com.kalvin.kvf.modules.sys.entity.User;
import org.springframework.stereotype.Service;
import com.kalvin.kvf.modules.xhs.entity.XhsIntentionCust;
import com.kalvin.kvf.modules.xhs.mapper.XhsIntentionCustMapper;

import java.util.List;

/**
 * <p>
 * 小红书客户表 服务实现类
 * </p>
 * @since 2023-12-01 11:32:06
 */
@Service
public class XhsIntentionCustServiceImpl extends ServiceImpl<XhsIntentionCustMapper, XhsIntentionCust> implements XhsIntentionCustService {

    @Override
    public Page<XhsIntentionCust> listIntentionCustPage(XhsIntentionCust intentionCust) {
        User user = ShiroKit.getUser();
        if(!user.getUsername().equals("admin")){
            intentionCust.setPhone(user.getPhone());
        }
        Page<XhsIntentionCust> page = new Page<>(intentionCust.getCurrent(), intentionCust.getSize());
        List<XhsIntentionCust> intentionCusts = baseMapper.selectIntentionCustList(intentionCust, page);
        return page.setRecords(intentionCusts);
    }
    @Override
    public void editnoStatus(List<Long> ids){
        for (Long id: ids) {
            XhsIntentionCust intentionCust = baseMapper.selectById(id);
            intentionCust.setStatus(0);//设置为未联系
            baseMapper.update(intentionCust,new UpdateWrapper<XhsIntentionCust>().lambda().eq(XhsIntentionCust::getId,id));
        }
    }

    @Override
    public void editStatus(List<Long> ids){
        for (Long id: ids) {
            XhsIntentionCust intentionCust = baseMapper.selectById(id);
            intentionCust.setStatus(1);//设置为已联系
            baseMapper.update(intentionCust,new UpdateWrapper<XhsIntentionCust>().lambda().eq(XhsIntentionCust::getId,id));
        }
    }
}
